package com.cxy.application;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class RegisterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_register);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        findViewById(R.id.btn_call).setOnClickListener((w)->{
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);
            EditText editText = findViewById(R.id.p_number);
            intent.setData(Uri.parse("tel:"+editText.getText().toString()));
            startActivity(intent);
        });

        findViewById(R.id.button1).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"1"));
        });

        findViewById(R.id.button2).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"2"));
        });

        findViewById(R.id.button3).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"3"));
        });

        findViewById(R.id.button4).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"4"));
        });

        findViewById(R.id.button5).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"5"));
        });

        findViewById(R.id.button6).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"6"));
        });

        findViewById(R.id.button7).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"7"));
        });

        findViewById(R.id.button8).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"8"));
        });

        findViewById(R.id.button9).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"9"));
        });

        findViewById(R.id.button0).setOnClickListener((w)->{
            EditText editText = findViewById(R.id.p_number);
            editText.setText(getNumber(editText,"0"));
        });
    }

    public String getNumber(EditText editText,String number){
        String string = editText.getText().toString();
        string+=number;
        return string;
    }
}